package web;

import pojo.User;
import service.LoginService;
import utils.MyBatisUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "RegisterServlet", value = "/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    LoginService service = new LoginService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        boolean result = service.register(new User(null, username, password));
        if(result){
            System.out.println("注册成功");
            response.getWriter().println("注册成功");
        }else {
            System.out.println("注册失败");
            response.getWriter().println("注册失败");
        }
    }
}
